package com.cecsmsserve.service.impl;

import com.cecsmsserve.entity.ServiceType;
import com.cecsmsserve.mapper.ServiceTypeMapper;
import com.cecsmsserve.service.IServiceTypeService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.cecsmsserve.util.result.CommonResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author 王郝浠
 * @since 2024-04-17
 */
@Service
public class ServiceTypeServiceImpl extends ServiceImpl<ServiceTypeMapper, ServiceType> implements IServiceTypeService {

    @Autowired
    ServiceTypeMapper mapper;

    @Override
    public CommonResult selectAllFather() {
        List<ServiceType> list=mapper.selectAllFather();
        CommonResult result=new CommonResult(list);
        if(list==null||list.size()==0){
            result.setNotFound();
        }
        return result;
    }

    @Override
    public CommonResult selectFather1() {
        List<ServiceType> list=mapper.selectFather1();
        CommonResult result=new CommonResult(list);
        if(list==null||list.size()==0){
            result.setNotFound();
        }
        return result;
    }

    @Override
    public CommonResult selectAllChildren() {
        List<ServiceType> list=mapper.selectAllChildren();
        CommonResult result=new CommonResult(list);
        if(list==null||list.size()==0){
            result.setNotFound();
        }
        return result;
    }

    @Override
    public CommonResult selectAllChildrenByFather(int id) {
        List<ServiceType> list=mapper.selectAllChildrenByFather(id);
        CommonResult result=new CommonResult(list);
        if(list==null||list.size()==0){
            result.setNotFound();
        }
        return result;
    }

    @Override
    public CommonResult selectChildren1ByFather(int id) {
        List<ServiceType> list=mapper.selectChildren1ByFather(id);
        CommonResult result=new CommonResult(list);
        if(list==null||list.size()==0){
            result.setNotFound();
        }
        return result;
    }

    @Override
    public CommonResult insert(ServiceType serviceType) {
        serviceType.setId(null);
        int i=mapper.insert(serviceType);
        CommonResult result=new CommonResult(i);
        if(i<=0){
            result.setNotInserted();
        }
        return result;
    }

    @Override
    public CommonResult update(ServiceType serviceType) {
        int i=mapper.updateById(serviceType);
        CommonResult result=new CommonResult(i);
        if(i<=0){
            result.setNotUpdate();
        }
        return result;
    }
}
